#pragma once 
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <cstdio>
#include <stdarg.h>

#define DEBUG 0
#define NOTICE 1
#define WARNNING 2
#define FATAL 3

const char* log_level[]={"DEBUG","NOTICE","WARNNING","FATAL"};
void logMessage(int level,const char* format,...)
{
    char* name=getenv("USER");
    va_list ap;
    va_start(ap,format);
    char logInfo[1024];
    vsnprintf(logInfo,sizeof(logInfo)-1,format,ap);
    FILE* out=(level==FATAL)?stderr:stdout;
    fprintf(out,"%s | %u | %s | %s\n",log_level[level],
    (unsigned int)time(nullptr),name==nullptr?"unknow":name,logInfo);  
}